<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .todo-contaienr{
      width: 800px;
      padding: 10px;
      border: 1px solid #999;
      border-radius: 10px;
      margin: 20px auto;
    }
    .todo-header{
      height: 30px;

      display: flex;
      align-items: center;
    }
    .todo-header .input{
      flex:1;
      border-radius: 4px;
      height: 80%;
      margin:0 10px;
    }
    .todo-content{
      margin-top: 20px;
    }
    .todo{
      padding: 10px;
      margin-top: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border: 1px solid #999;
      border-radius: 5px;
    }
    .content{
      flex: 1;
    }
    .zanwu{
      line-height: 30px;
      font-size: 20px;
      text-align: center;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="todo-contaienr">
      <div class="todo-header">
        <input type="text" class="input" v-model.trim="todoInput">
        <button class="add" @click="addTodo">添加</button>
      </div>
      <div class="todo-content">
        <div class="zanwu" v-if="todos.length === 0">暂无待办事项</div>
        <div class="todo" v-for="(todo,index) in todos">
          <p class="content">
            {{todo.content}}
          </p>
          <div>
            <button @click="delTodo(index)">删除</button>
            <button>点击已完成</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          // 绑定输入输入框
          todoInput: '',
          // 待办事项列表
          todos: [
            {
              content: '待办事项1',
              done: false
            }
          ]
        }
      },
      methods: {
        // 新增待办事项
        addTodo(){
          if(this.todoInput === '') {
            return false;
          }
          this.todos.push({
            content: this.todoInput,
            done: false
          })
          // 清空输入框value 方便新增下一个
          this.todoInput = '';
        },
        // 删除待办事项
        delTodo(index){
          if(confirm('确认删除吗?')){
            this.todos.splice(index, 1)
          }
        }
      }
    })
    app.mount('#app')
  </script>
</body>
</html>